package com.jml.zlhq.app.adapter;

import java.util.List;

import org.json.JSONObject;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jml.zlhq.app.R;
import com.jml.zlhq.app.AppContext;

public class MainTanDianAdapter extends IBaseAdapter {
	private List<JSONObject> itemList;
	private AppContext appContext;
	@SuppressWarnings("unused")
	private Activity activity;

	public MainTanDianAdapter(Activity activity, List<JSONObject> itemList) {
		this.itemList = itemList;
		this.appContext = (AppContext) activity.getApplication();
		this.activity = activity;
	}

	@Override
	public int getCount() {
		int count = itemList == null ? 0 : itemList.size();
		count++;
		return count;
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public int getItemViewType(int position) {
		int type = 0;
		if(position==0){
			type=0;
		}else{
			type = 1;
		}
		return type;

	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}
	
	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		if(position==0){
			convertView = createTopItem(position, convertView, parent);
		}else{
			convertView = createItem(position, convertView, parent);
		}
		return convertView;
	}
	
	static class ItemTopHolder {
		public TextView jinbi,jine,yhk,zfb;
	}
	private View createTopItem(int position, View convertView, final ViewGroup parent){
		ItemTopHolder holder = null;
		if(convertView==null){
			holder = new ItemTopHolder();
			int main_tandian_item = R.layout.main_tandian_item_top;
			convertView = LayoutInflater.from(appContext).inflate(main_tandian_item, null);
			holder.jinbi = (TextView) convertView.findViewById(R.id.tandian_itemtop_jinbi);
			holder.jine = (TextView) convertView.findViewById(R.id.tandian_itemtop_jine);
			holder.yhk = (TextView) convertView.findViewById(R.id.tandian_itemtop_yhk);
			holder.zfb = (TextView) convertView.findViewById(R.id.tandian_itemtop_zfb);
			convertView.setTag(holder);
		}else{
			holder = (ItemTopHolder) convertView.getTag();
		}
		
		return convertView;
	}
	
	static class ItemHolder {
		public TextView title,size,date,nomore;
	}
	private View createItem(int position, View convertView, final ViewGroup parent){
		ItemHolder holder = null;
		if(convertView==null){
			holder = new ItemHolder();
			int main_tandian_item = R.layout.main_tandian_item;
			convertView = LayoutInflater.from(appContext).inflate(main_tandian_item, null);
			holder.title = (TextView) convertView.findViewById(R.id.main_tandian_item_title);
			holder.size = (TextView) convertView.findViewById(R.id.main_tandian_item_size);
			holder.date = (TextView) convertView.findViewById(R.id.main_tandian_item_date);
			holder.nomore = (TextView) convertView.findViewById(R.id.main_tandian_item_nomore);
			convertView.setTag(holder);
		}else{
			holder = (ItemHolder) convertView.getTag();
		}
		
		return convertView;
	}
}
